﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using OMS.Models;
using OMS.OMSService;

namespace OMS.Controllers
{
    public class UserController : Controller
    {
        //
        // GET: /User/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult InitSession(LogOnModel model)
        {
            if (ModelState.IsValid)
            {
                //FormsA
            }
            return View();
        }

        public ActionResult Filter(string filterBy, string searchString)
        {
            List<ItemModelView> itemModelViews = new List<ItemModelView>();
            List<ItemModel> itemModels = new List<ItemModel>();
            if (!String.IsNullOrEmpty(searchString))
            {
                Service1 service = new Service1();
                switch (filterBy)
                {
                    case "name":
                        itemModels = service.FilterByName(searchString).ToList();
                        break;
                    case "description":
                        itemModels = service.FilterByDescription(searchString).ToList();
                        break;
                }
            }
            foreach(ItemModel itemModel in itemModels)
            {
                itemModelViews.Add(new ItemModelView(itemModel));
            }
            return View(itemModelViews);
        }
    }
}
